package org.fly.jingwei.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;

import org.fly.jingwei.ext.utils.JsonUtils;
import org.springframework.core.annotation.Order;

/**
 * @author leo.jie (weixiao.me@aliyun.com)
 * @version 1.0
 * @organization bigdata
 * @website https://www.jielongping.com
 * @date 2020/5/30 8:42 下午
 * @since 1.0
 */
@Order(1)
@WebFilter(filterName = "firstFilter", urlPatterns = "/*")
public class GlobalFilter implements Filter {
    @Override
    public void destroy() {

    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain fc) throws IOException, ServletException {
        if (res instanceof HttpServletResponse) {
            HttpServletResponse response = (HttpServletResponse) res;
            JsonUtils.putResponse(response);
        }

        fc.doFilter(req, res);
    }

    @Override
    public void init(FilterConfig fc) throws ServletException {

    }
}
